<%@ taglib uri="/WEB-INF/myfaces_html.tld" 	prefix="h" %>
<%@ taglib uri="/WEB-INF/myfaces_core.tld" 	prefix="f" %>
<%@ taglib uri="/WEB-INF/tomahawk.tld"     	prefix="t" %>
<%@ page import="it.azienda.framework.utilita.Utilita" %>
<%@ page import="it.azienda.moretti.modello.BeanComune" %>
<%@ page import="java.util.*" %>    
<%@ page import="javax.faces.context.FacesContext" %>
<%
    java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle(FacesContext.getCurrentInstance().getApplication().getMessageBundle(), FacesContext.getCurrentInstance().getApplication().getDefaultLocale());
    String versioneSw = bundle.getString("moretti_titolo");
%>     

<%
    String lookup = (String) request.getParameter("lookup");
    if (lookup == null && Utilita.getSession().getAttribute("lookup") != null) {
        lookup = (String) session.getAttribute("lookup");
        session.setAttribute("lookup", lookup);
    } else {
        session.setAttribute("lookup", lookup);
    }
%>      

<f:view>   
    <html lang="it">
        <head>
            <title><%=versioneSw%> - Lookup Comuni</title>   
            <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" >
            <link rel="stylesheet" href="../moretti.css" type="text/css">
        </head>        
        <body>                
            <h:form id="uno">
                <table class="lookUp">
                    <tr>     
                        <td class="etichettaIntestazioneLookUp" colspan="5" align="center"><strong><t:outputLabel for="ricerca" value="Modulo di Ricerca Comuni" /></strong></td>                        
                    </tr>     

                    <tr>     
                        <td class="lookUptd"><strong><t:outputLabel for="prop1" value="Comune:" /></strong></td>            
                        <td><t:inputText id="prop1" value="#{beanFind.prop1}" size="30" maxlength="30" styleClass="viewEtichetta" onchange="this.value=this.value.toUpperCase()" /></td>
                    </tr>                 

                    <tr>     
                        <td class="lookUptd"><strong><t:outputLabel for="prop2" value="Provincia:" /></strong></td>
                        <td><t:inputText id="prop2" value="#{beanFind.prop2}" size="30" maxlength="30"  styleClass="viewEtichetta" onchange="this.value=this.value.toUpperCase()" /></td>                
                    </tr>                

                    <t:inputHidden id="tabella" value="comuni" />                    
                    <t:inputHidden id="bean" value="BeanComune" />                    
                    <t:inputHidden id="proprieta" value="descrizione,tableProvince-BeanProvincia-descrizione-provincia_id"/>          

                    <tr>
                        <td>
                            <t:commandButton value="Invia" actionListener="#{dettaglioComune.cercaOggettiLookup}" immediate="true" >                         
                            </t:commandButton>                       
                        </td>                              
                        <td>
                            <t:commandButton value="Chiudi" action="#{dettaglioComune.resettaLookup}" onclick="javascript:window.close()" immediate="true" >                         
                            </t:commandButton>                       
                        </td>                                                 
                    </tr>                
                </table>
            </h:form>   


            <h:form id="erroriDataBase" rendered="false">
            <td align="left" class="messaggiErrore" height="2px">           
                <h:messages  style="color: red" showDetail="true" showSummary="false"/>
            </td>
        </h:form>   

        <h:form >
            <div  style="overflow: scroll; height: 150px; white-space: nowrap; wrap: off">
                <t:dataTable id="tabella2" var="lista" value="#{listaLookup}" preserveDataModel="true"           
                             styleClass="dataTableGestisci_TableLookUp" 
                             headerClass="dataTableGestisci_HeaderLookUp"
                             rowClasses="dataTableGestisci_Row1LookUp, dataTableGestisci_Row2LookUp"          
                             columnClasses="dataTableGestisci_ColumnLookUp" 
                             rowOnMouseOver="this.style.backgroundColor='#FFCC00'"
                             >  


                    <t:column width="10%">
                        <f:facet name="header"  >
                            <t:outputText value="Descrizione" />
                        </f:facet>
                        <t:outputText value="#{lista.descrizione}" /> 
                    </t:column>

                    <t:column width="10%">
                        <f:facet name="header"  >
                            <t:outputText value="Cap" />
                        </f:facet>
                        <t:outputText value="#{lista.cap}" /> 
                    </t:column>

                    <t:column width="10%">
                        <f:facet name="header"  >
                            <t:outputText value="Provincia" />
                        </f:facet>
                        <t:outputText value="#{lista.beanProvincia.descrizione}" /> 
                    </t:column>

                    <t:column width="1%">
                        <t:inputHidden id="idLookup" value="#{lista.id}" /> 
                    </t:column>

                    <t:column width="10%">
                        <%if (lookup.equals("descrizioneComune_Residenza")) {%>
                        <t:commandButton value="INVIA" action="#{dettaglioComune.resettaLookup}" onclick="valorizeOpener('descrizioneComune_Residenza','#{lista.descrizioneFind}')" immediate="true">                                                         
                        </t:commandButton>     
                        <%} else if (lookup.equals("descrizioneComune_Nascita")) {%>
                        <t:commandButton value="INVIA" action="#{dettaglioComune.resettaLookup}" onclick="valorizeOpener('descrizioneComune_Nascita','#{lista.descrizioneFind}')" immediate="true">                                                         
                        </t:commandButton>     
                        <%} else if (lookup.equals("descrizioneComune")) {%>
                        <t:commandButton value="INVIA" action="#{dettaglioComune.resettaLookup}" onclick="valorizeOpener('descrizioneComune','#{lista.descrizioneFind}')" immediate="true">                                                         
                        </t:commandButton>     
                        <%} else if (lookup.equals("descrizioneComune_Arrivo")) {%>
                        <t:commandButton value="INVIA" action="#{dettaglioComune.resettaLookup}" onclick="valorizeOpener('descrizioneComune_Arrivo','#{lista.descrizioneFind}')" immediate="true">                                                         
                        </t:commandButton>     
                        <%} else if (lookup.equals("descrizioneComune_Partenza")) {%>
                        <t:commandButton value="INVIA" action="#{dettaglioComune.resettaLookup}" onclick="valorizeOpener('descrizioneComune_Partenza','#{lista.descrizioneFind}')" immediate="true">                                                         
                        </t:commandButton>     
                        <%}%>                            </t:column>                 
                </t:dataTable>  
            </div>
        </h:form>       

        <script type="text/javascript">
            function valorizeOpener(lookup, descComune)
            {
                propLookup = 'formLookup:' + lookup;
                window.opener.document.getElementById(propLookup).focus()
                window.opener.document.getElementById(propLookup).value = descComune
                window.opener.document.formLookup.submit()
                window.close()
            }
        </script>
    </body>
</html>
</f:view>
